Component({
  data: {
    selected: 0,
    color: "#7A7E83",
    selectedColor: "#3cc51f",
    is_show:0,
    cart_num:0
  },
  attached() {
    this.getNav();
  },
  methods: {
    getNav: function () {
      var that = this;
      var nav = wx.getStorageSync("_navbar");
      if (nav && nav != '' && nav != undefined) {
        that.setData({
          nav_list: nav,
          selected: getApp().globalData.nav_index
        })
      } else {
        getApp().request({
          url: getApp().api.default.navbar,
          success: function (e) {
            that.setData({
              nav_list: e.data,
              selected: getApp().globalData.nav_index
            })
          }
        });
      }
      
    },
    switchTab(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      getApp().globalData.nav_index = data.index
      if (url.indexOf('pages/index/index') >= 0 ||
        url.indexOf('pages/cat/cat') >= 0 ||
        url.indexOf('pages/cart/cart') >= 0 ||
        url.indexOf('pages/posts/index') >= 0 ||
        url.indexOf('pages/user/user') >= 0
      ) {
        wx.switchTab({ url })
      }else {
        wx.navigateTo({
          url: url,
        });
      }
      
    },
    switchTo(e) {
      const data = e.currentTarget.dataset
      const url = data.path
      getApp().globalData.nav_index = data.index
      wx.redirectTo({
        url: url,
      });
    },
  },
})